$(function() {
	$(".cell-item").click(function() {
		$(this).find("input").focus()
	})
	$("#cx").click(function() {
		$('#J_List').unbind()
		$('#J_ListContent').html("")
		$(".list-donetip").css("display", "none")
		var name = $("#userName").val()

		abb(name, '')
	})
	var a = ''
	var code=sessionStorage.getItem("code")
	abb(a)
	function abb(a) {
		var page = 1,
			pageSize = 5;
		$('#J_List').infiniteScroll({
			binder: $("#J_List"),
			pageSize: pageSize,
			initLoad: true,
			loadingHtml: '<strong>加载中...</strong>',
			loadListFn: function() {
				var def = $.Deferred();
				$.ajax({
					url: 'selectActivityByUserDept',
					dataType: 'json',
					type: 'POST',
					data: {
						activityType:code,
						start: page,
						end: page + pageSize - 1,
						name: a,
					},
					success: function(data) {
				/*alert(JSON.stringify(data))*/
						var rel=data.data
						var num = rel.total
						$(".num").val(num)
						var html = ''
						for(var i = 0; i < rel.rows.length; i++) {
							html += '<li><h3>姓名：' + add(rel.rows[i].姓名) + '<span>' +rel.rows[i].登记时间 + '</span></h3>';
							html += '<p>奖品：' + add(rel.rows[i].奖品) + '</p>';
							html += '<p>登记人：' + add(rel.rows[i].登记人) + '</p>';
							html += '<h4 class="cell-right cell-arrow">';
							if(code=='17'){
								
							}else{
								html += '<span class="xg" id_prikey="' + rel.rows[i].id_prikey + '" hdh="' + rel.rows[i].活动类型 + '"><i class="icon-feedback"></i>修改</span>';
							}
							
							html += '<a id_prikey="' + rel.rows[i].id_prikey + '" class="ck" jqxh="' + rel.rows[i].活动号 + '">查看详情 </a></h4>'
						}
						$('#J_ListContent').append(html);

						if(rel.rows.length == 0) {
							def.resolve(['']);
						} else {
							def.resolve(rel.rows);
						}
						page = page + pageSize

					}
				});
				return def.promise();
			}
		});
	}
	$('#J_ListContent').delegate('.ck', 'click', function() {
		var id_prikey = $(this).attr("id_prikey")
		sessionStorage.setItem("id_prikey", id_prikey)
		window.location.href = "ck"
	})
	$('#J_ListContent').delegate('.xg', 'click', function() {
		var id_prikey = $(this).attr("id_prikey")
		sessionStorage.setItem("id_prikey", id_prikey)
		var hdh=$(this).attr("hdh")
		if(hdh=='13'||hdh=='15'){
			window.location.href = "dd_xg?id="+id_prikey
		}else if(hdh=='12'){
			window.location.href = "kmhdj?id="+id_prikey
		}else if(hdh=='14'){
			window.location.href = "dd_hbxx?id="+id_prikey
		}else if(hdh=='16'){
			window.location.href = "input2?id_prikey="+id_prikey
		}else{
			window.location.href = "xg"
		}
		
	})
	function add(row){
		
		if(row==undefined||row=='null'){
			return ""
		}else{
			return row
		}
	}
})